package com.sumainfor.pc.market.service.gmio;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.market.dao.FinancialForGmioProviderMapper;
import com.sumainfor.pc.market.feign.Zfeign.ZzuulFeign;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @Author Eddy·Chen
 * @Email 835033913@qq.com
 * @Create 2019-04-18 14:31
 */
@Service
@Transactional(rollbackFor = Exception.class)
@Log4j2
public class FinancialForGmioProviderService {

    @Autowired
    private FinancialForGmioProviderMapper mapper;

    @Autowired
    private ZzuulFeign zuulFeign;

    /**
     * 筛选小区数据 返回小区编号
     *
     * @param params
     * @return
     */
    public List<Map<String, Object>> filterHousingData(Map<String, Object> params) {
        return mapper.filterHousingData(params);
    }

    /**
     * 根据业主编号 查询合同的信息
     *
     * @param ownerId
     * @return
     */
    public Map<String, Object> selectOwnerPactInfo(String ownerId) {
        return mapper.selectOwnerPactInfo(ownerId);
    }


    /**
     * 查询租客合同信息
     *
     * @param tenantId
     * @param hinfoId
     * @return
     */
    public Map<String, Object> getTenantPactId(String tenantId, String hinfoId) {
        return mapper.getTenantPactId(tenantId, hinfoId);
    }

    /**
     * 查询房源数据
     *
     * @param hInfoId
     * @return
     */
    public Map<String, Object> selectHousingInfo(String hInfoId) {
        Map<String, Object> info = mapper.selectHousingInfo(hInfoId);
        //查询服务中心名称
        String miId = MapUtils.getString(info, "MiId");
        Map<String, Object> map = zuulFeign.getDeptInfoById(miId);
        if (MapUtils.isEmpty(map)) {
            return null;
        }
        info.put("CenterName", map.get("name"));
        return info;
    }


    /**
     * 根据Type类型 与编号查询 数据
     *
     * @param type 1. 项目 2. 房源
     * @param id
     * @return
     */
    public Map<String, Object> selectHousingForType(Integer type, String id) {
        Map<String, Object> data = null;
        //1. 项目 2. 房源
        switch (type) {
            case 1:
                data = mapper.getProjectById(id);
                break;
            case 2:
                data = mapper.getHousingInfoById(id);
                if (MapUtils.isNotEmpty(data)) {
                    data.put("Type", ((Integer) data.remove("IfOperaType")).equals(0) ? "合租" : "整租");
                }
                break;
        }
        return data;
    }

    /**
     * 查询信息
     * @param params
     * @return
     */
    public List<Map<String,Object>> getHousingInfoByIdsss(Map<String,Object> params){
        return mapper.getHousingInfoByIdsss(params);
    }

    /**
     * 筛选小区编号 根据服务中心编号集合
     *
     * @param hIds
     * @param miIds
     * @return
     */
    public JsonResult filterCenterForHousing(List<String> hIds, List<Integer> miIds) {
        return JsonResult.success(mapper.selectFilterHousingForCenter(hIds, miIds));
    }

}
